package cz.muni.fi.pa165.entity;

import cz.muni.fi.pa165.enums.AdminRole;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;

/**
 * Entity class Employee
 * @author Jakub Janco
 */
@Entity
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date birthDate;
    
    @Enumerated(value = EnumType.STRING)
    private AdminRole role;
    private String password;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public AdminRole getRole() {
        return role;
    }

    public void setRole(AdminRole role) {
        this.role = role;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public Date getBirthDate() {
        if (birthDate == null) {
            return null;
        }
        return (Date) birthDate.clone();
    }

    public void setBirthDate(Date birthDate) {
        if (birthDate == null) {
            this.birthDate = null;
        } else {
            this.birthDate = new Date(birthDate.getTime());
        }
    }

    public Long getId() {
        return id;
    }

    /**
     * Sets unique id
     * @param id Employee id
     * @throws IllegalArgumentException if id was set before method called
     */
    public void setId(Long id) {
        if (this.id != null) {
            throw new IllegalArgumentException("id was already set.");
        }
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Employee other = (Employee) obj;
        if (this.id == null || !this.id.equals(other.id)) {
            return false;
        }
        return true;
    }  

    @Override
    public String toString() {
        return "cz.muni.fi.pa165.Employee[ id=" + id + " ]";
    }

}
